package com.atguigu.gulimall.product.web;

import com.atguigu.gulimall.product.service.SkuInfoService;
import com.atguigu.gulimall.product.vo.SkuItemVO;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.concurrent.ExecutionException;

/**
 * @author : wenchao.long
 * @date : Created in 2021/8/5 13:57 周四
 * @description :
 */
@Controller
@Slf4j
@AllArgsConstructor
public class ItemController {

    private final SkuInfoService skuInfoService;

    /**
     * 展示当前sku的详情
     *
     * @param skuId skuId
     * @return String
     */
    @GetMapping("/{skuId}.html")
    public String skuItem(@PathVariable Long skuId,
                          Model model) throws ExecutionException, InterruptedException {
        log.info("准备查询" + skuId + "详情");
        SkuItemVO vo = skuInfoService.item(skuId);
        model.addAttribute("item", vo);
        return "item";
    }
}
